< previous page page_357 next page >

Page 357
0357-01.jpg
Figure 9.21.
Viewing the property list
for a saved QueryDef.
The ODBCDirect Connection Data Object
The Connection object is new to Visual Basic 5.0. This data object is part of the ODBCDirect data access model. This model allows programmers to access ODBC data sources without first defining a Microsoft Jet data object. The ability to open a direct connection to ODBC instead of first opening a Microsoft Jet session provides added flexibility to your programs.
The process of creating and using a Connection object begins at the workspace level. When you create a new workspace, you must explicitly mark it as an ODBCDirect workspace. You can then perform an OpenConnection method to open a new connection to an ODBC data source. Once the connection has been established, you can use the OpenRecordset, Execute, CreateQueryDef, and Close methods with which you are already familiar.
Add a new button to the form and set its Name property to cmdConnection and its Caption to Connection. Now enter the code from Listing 9.22 into the cmdConnection_Click event.
Type.gifListing 9.22. Coding the cmdConnection_Click event.
Private Sub cmdConnection_Click()
    '
    ' show use of ODBCDirect Connection object
    '
    Dim ws As Workspace
    Dim co As Connection
    '
    Dim strWSName As String
    Dim strCOName As String
    Dim strDSN As String
    Dim strDBQ As String
    Dim strCOConnect As String
    Dim strMsg As String
    '
    ' init vars
continues

 
< previous page page_357 next page >

If you like this book, buy it!